<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function fib(n) {
            if (n <=2) return 1;

            return fib(n - 1) + fib(n - 2);
        }

        console.log(fib(10));

        // 封装一个函数,实现x的n次方

        function pow(x, n) {
            if (n === 0) return 1;

            return x * pow(x, n - 1);
        }

        console.log(pow(2, 3));

        // 斐波那契数列实现

        function fib2(n) {
            if (n <= 2) return 1;

            let a = 1;
            let b = 1;
            let c = 0;

            for (let i = 3; i <= n; i++) {
                c = a + b;
                a = b;
                b = c;
            }

            return c;
        }
        console.log(fib2(10));
    </script>
</body>
</html>